using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class WinPanel : MonoBehaviour
{
    public Button m_BtnConfirm;
    public Text m_Mode;
    public Text m_Time;
    public Text m_NewLog;


    public void Show(int time, Action clickCallback)
    {
        gameObject.SetActive(true);

        m_ClickCallback = clickCallback;

        string modeStr;
        string modePrefStr;
        if (GameMode.Instance.CurMode == EGameMode.Junior)
        {
            modeStr = "初级";
            modePrefStr = "Junior_Time";
        }
        else if (GameMode.Instance.CurMode == EGameMode.Senior)
        {
            modeStr = "高级";
            modePrefStr = "Senior_Time";
        }
        else if (GameMode.Instance.CurMode == EGameMode.Expert)
        {
            modeStr = "专家";
            modePrefStr = "Expert_Time";
        }
        else
        {
            modeStr = "自定义";
            modePrefStr = "Customer_Time";
        }
        m_Mode.text = modeStr;

        m_Time.text = string.Format("{0}秒", time);

        if (GameMode.Instance.CurMode != EGameMode.Customer)
        {
            int lastTime = PlayerPrefs.GetInt(modePrefStr, 99999);
            m_NewLog.gameObject.SetActive(time < lastTime);
            if (time < lastTime)
            {
                PlayerPrefs.SetInt(modePrefStr, time);
            }
        }
    }

    public void Hide()
    {
        gameObject.SetActive(false);
    }
    //=========================================公私分界线==================================================

    private Action m_ClickCallback;
    void Awake()
    {
        gameObject.SetActive(false);
        m_NewLog.gameObject.SetActive(false);
        m_BtnConfirm.onClick.AddListener(OnBtnConfirmClick);
    }

    void OnBtnConfirmClick()
    {
        Hide();
        if (m_ClickCallback != null) m_ClickCallback();
    }
}
